// 用户信息
import { createSlice } from "@reduxjs/toolkit";
import { clear } from "@testing-library/user-event/dist/clear";
export let userSlice = createSlice({
    name: 'userSlice',
    initialState: {
        user: localStorage.getItem('hr-user')?JSON.parse(localStorage.getItem('hr-user')):{},
        token: localStorage.getItem('hr-token')
    },
    reducers: {
        setUser(state,action){
            localStorage.setItem('hr-user', JSON.stringify(action.payload))
            state.user = { ...action.payload}
        },
        setToken(state,action){
            localStorage.setItem('hr-token', action.payload)
            state.token = action.payload
        }
    }
})

// 可以单独导出修改数据函数，便于其他地方使用
export let { setToken } = userSlice.actions